<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;


use App\Models\Admin\RuzhuMerchantBasic;
use App\Models\Admin\Order;

class MerchantController extends CommonController{

	protected $model;

	public function __construct()
	{
		parent::__construct();
		$this->model = new RuzhuMerchantBasic;
	}


	/**
	 * banner图添加/修改
	 */
	public function edit(Request $request)
	{
		if($request->isMethod('post')) {


			$validator = \Validator::make($request->all(),[
				'merchant_name'	=> 'required',
				'short_name'	=> 'required',
				'merchant_address' => 'required',
				'service_phone'  => 'required',
				'open_time' => 'required',
				'logo' => 'required',
			],[
				'merchant_name.required'	=> '请填写店铺名称',
				'short_name.required'	=> '请填写简称',
				'merchant_address.required' => '请填写店铺详细地址',
				'service_phone.required'  => '请填写服务电话',
				'open_time.required' => '请填写营业时间',
				'logo.required' => '请上传图片',
			]);

			if($validator->fails()){
				$this->ajax_error($validator->errors()->first());
			}

			$data = $request->only('merchant_name', 'short_name', 'merchant_address', 'service_phone', 'open_time', 'logo');

			if(!$this->model->where(array('id' => $this->merchant_id))->update($data)) $this->ajax_error('操作失败，请重试');
			$this->ajax_success('提交成功');
			
		}else{
			$data = $this->model->find($this->merchant_id, ['ID', 'SHORT_NAME', 'MERCHANT_NAME', 'MERCHANT_ADDRESS', 'SERVICE_PHONE', 'OPEN_TIME', 'LOGO']);
			return view('admin.merchant.edit')->with(['data' => $data]);
		}

	}


     /**
     * 商家线下订单列表
     */
    public function orderList(Request $request){
    	//商家ID
    	$sid = $_SESSION['admin_uid'];
        $orderModel = new Order();
        $order_no = $request->input('order_no');
        $pay_state = $request->input('pay_state');
        $order_list = $orderModel->get_lineorder_list($order_no,$pay_state,$sid);

        return view('admin.order.order_list',['data'=>$order_list]);
    }

     /**
     * @param Request $request
     * 删除订单
     */
    public function orderDel(Request $request){
        $id = $request->input('id');
        $result = DB::table('vshops_order')->where('id',$id)->delete();
        if($result){
            $this->ajax_success('删除成功',$result);
        }
        $this->ajax_error('删除失败',$result);
    }


}